package com.xuecheng.web.exception;

import com.xuecheng.commons.enums.ErrorCode;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//统一异常处理类
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 异常处理方法
     */
    @ExceptionHandler(value = RuntimeException.class)
    public ResponseResult exception(RuntimeException e){
        return ResponseResult.errorResult(ErrorCode.ERROR);
    }

    //参数 业务方法 自定义异常
    @ExceptionHandler(value = BusinessException.class)
    public ResponseResult businessException(BusinessException e){
        ErrorCode errorCode = e.getErrorCode();
        return ResponseResult.errorResult(errorCode);
    }
}
